package common.utils;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public abstract class FileUtils {
    /**
     *  打包为 zip 文件
     * @param file 待打包的文件
     * @param zos zip zip输出流
     */
    public static void doZip(File file, ZipOutputStream zos) throws IOException {
        //假设是文件，写入到 zip 流中
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
        zos.putNextEntry(new ZipEntry(file.getName()));
        byte[] buffer = new byte[1024];
        int r ;
        while ((r = bis.read(buffer)) != -1) {
            zos.write(buffer, 0, r);
        }

    }
}
